﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using DualityClient.Screens;
using DualityEngine.Business;

namespace DualityClient
{
    public class ScreenManager
    {
        private Dictionary<string, Screen> screens;
        private static ScreenManager instance = new ScreenManager();
        private Screen activescreen;
        private MouseCursor mousecursor;

        public static ScreenManager Instance
        {
            get
            {
                return instance;
            }
        }

        protected ScreenManager()
        {
            screens = new Dictionary<string, Screen>();
            screens.Add("GameScreen", new LevelScreen());
            screens.Add("LoginMenu", new LoginScreen());

            activescreen = screens["LoginMenu"];
            mousecursor = new MouseCursor();
        }

        public Screen GetScreen(string name)
        {
            return screens[name];
        }

        public void Update(GameTime gameTime)
        {
            switch (GameState.Instance.gameState)
            {
                case eGameState.LOGINMENU:
                    if (activescreen.GetType() != typeof(LoginScreen))
                        activescreen = new LoginScreen();
                    break;
                case eGameState.INGAME:
                    if (activescreen.GetType() != typeof(LevelScreen))
                        activescreen = new LevelScreen();
                    break;
            }

            //Check als het null is
            if (activescreen != null)
                activescreen.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            switch (GameState.Instance.gameState)
            {
                case eGameState.LOGINMENU:
                    if (activescreen.GetType() != typeof(LoginScreen))
                        activescreen = new LoginScreen();
                    break;
                case eGameState.INGAME:
                    if (activescreen.GetType() != typeof(LevelScreen))
                        activescreen = new LevelScreen();
                    break;
            }

            ResourceManager.Instance.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.SaveState);
            //Check als het null is
            if (activescreen != null)
                activescreen.Draw(gameTime);
            mousecursor.Draw(gameTime);
            ResourceManager.Instance.spriteBatch.End();
        }
    }
}
